---
description: Create a one-off scheduled event with Hasura
keywords:
  - hasura
  - docs
  - one off scheduled event
  - scheduled trigger
  - create
sidebar_position: 7
sidebar_label: Create a one-off Scheduled Event
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import Thumbnail from '@site/src/components/Thumbnail';

# Create a One-off Scheduled Event

## Introduction

One-off scheduled events are used to reliably trigger an HTTP webhook to run custom business logic at a particular point
in time. For example, you can create a scheduled event to send a reminder email two weeks after a user signs up.

To add a one-off scheduled event, follow these steps:

## Step 1: Define the scheduled event

The following fields for required to define a scheduled event:

- **Webhook**: The HTTP endpoint that should be triggered.
- **Time**: The time to trigger the event.
- **Payload**: The JSON payload which will be sent to the webhook.

<Tabs groupId="user-preference" className="api-tabs">
<TabItem value="console" label="Console">

Navigate to `Events > One-off Scheduled Events > Schedule an event` in your Hasura Console.

<Thumbnail src="/img/event-triggers/one-off.png" alt="Adding a one-off scheduled event" width="900px" />

In the form opened by the above step, fill out the fields defined above:

<Thumbnail
  src="/img/event-triggers/define-one-off-event.png"
  alt="Defining the scheduled event"
  width="550px"
/>
</TabItem>
<TabItem value="cli" label="CLI">

One-off scheduled events cannot be set using the CLI as they are not tracked as a part of Hasura Metadata.

</TabItem>
<TabItem value="api" label="API">

You can define a scheduled event via the
[create_scheduled_event](/api-reference/metadata-api/scheduled-triggers.mdx#metadata-create-scheduled-event) metadata
API:

```http
POST /v1/metadata HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin

{
   "type": "create_scheduled_event",
   "args": {
      "webhook": "https://send-email.com",
      "schedule_at": "2022-06-18T18:45:00Z",
      "payload": { "email": "bob@ross.com" }
   }
}
```

</TabItem>
</Tabs>

## Step 2: Define advanced options (Optional)

If you like, you can also define advanced values:

- **Headers**: List of headers to be sent to the webhook.
- **Retry configuration**: In case the call to the webhook fails.
- **Comment**: Custom description of the Scheduled Trigger.

<Tabs groupId="user-preference" className="api-tabs">
<TabItem value="console" label="Console">

Expand the `Advanced` section.

<Thumbnail
  src="/img/event-triggers/advanced-one-off.png"
  alt="Defining advanced options for a scheduled event"
  width="700px"
/>
</TabItem>
<TabItem value="cli" label="CLI">

One-off scheduled events cannot be set using the CLI as they are not tracked as a part of Hasura Metadata.

</TabItem>
<TabItem value="api" label="API">

You can define advanced options when defining a scheduled event via the
[create_scheduled_event](/api-reference/metadata-api/scheduled-triggers.mdx#metadata-create-scheduled-event) metadata
API:

```http
POST /v1/metadata HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin

{
   "type": "create_scheduled_event",
   "args": {
      "webhook": "https://send-email.com",
      "schedule_at": "2022-06-18T18:45:00Z",
      "payload": {
            "email": "bob@ross.com"
      },
      "headers": [
            {
               "name": "key",
               "value": "value"
            }
      ],
      "retry_conf": {
            "num_retries": 3,
            "timeout_seconds": 120,
            "tolerance_seconds": 21675,
            "retry_interval_seconds": 12
      },
      "comment": "sample scheduled event comment"
   }
}
```

</TabItem>
</Tabs>

## Schedule & logs

Once you've created your Scheduled Trigger, you can see `Pending events`, `Processed events`, and `Invocation logs` in
their respective tabs.

<Thumbnail src="/img/event-triggers/pending-one-off.png" alt="Schedule and logs for scheduled events" width="1200px" />

:::info Note

A scheduled event will be delivered within ten seconds of when it's scheduled. For example, if you schedule an event at
`09:24:10`, it will be delivered between `09:24:10` and `09:24:20`.

This is because Hasura currently checks for events to be delivered at 10 second intervals. This interval will be made
configurable soon.

:::
